package cn.chaos.nio02;

import java.io.FileInputStream;
import java.io.IOException;
import java.nio.channels.Channels;
import java.nio.channels.FileChannel;
import java.nio.channels.WritableByteChannel;

public class ChannelTransfer {

    public static void main(String[] args) throws Exception {
        
//        if (args.length == 0) {
//            System.err.println("Usage: filename ...");
//            return ;
//        }
        
        catFiles(Channels.newChannel(System.out), new String[] {"D:\\Books\\笔记\\React-03.md"} );        
    }
    
    private static void catFiles(WritableByteChannel target, 
            String[] files) throws IOException {
        
        for (int i = 0; i < files.length; i++) {
            try (FileInputStream fis = new FileInputStream(files[i]);
                    FileChannel channel = fis.getChannel()) {
                channel.transferTo(0 , channel.size(), target);
            }
        }
    }
}
